package com.szxy.miaosha.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.ToString;

/**
 * @Auther:wzer
 * @Date:2020/9/5
 * @Description:com.szxy.miaosha.utils
 * @Version:1.0
 **/
@ToString
@Data
public class CodeMsg {

    public final static CodeMsg SERVER_ERROR = new CodeMsg(500100, "服务后端错误");
    public final static CodeMsg BIND_ERROR = new CodeMsg(5001002, "参数错误: %s");
    // 登录模板 5002xxx
    public final static CodeMsg LOGIN_ERROR = new CodeMsg(500200, "登录错误");
    public final static CodeMsg LOGINVO_NULL_ERROR = new CodeMsg(500201, "登录参数不存在");
    public final static CodeMsg MOBILE_NULL_ERROR = new CodeMsg(500202, "手机号不存在");
    public final static CodeMsg MOBILE_VALIDATE_ERROR = new CodeMsg(500203, "手机号格式错误");
    public final static CodeMsg PASSWORD_NULL_ERROR = new CodeMsg(500204, "密码不存在");
    public final static CodeMsg USER_NOT_EXIST = new CodeMsg(500205, "用户不存在");
    public final static CodeMsg PASSWORD_ERROR = new CodeMsg(500206, "密码不匹配");
    public final static CodeMsg LOGIN_SUCCESS = new CodeMsg(0, "用户名密码匹配成功");

    // 用户模板 5003xx
    public final static CodeMsg ADD_USER_ERROR = new CodeMsg(500300, "添加用户失败");

    // 商品模块 5004xx
    public static final CodeMsg STOCK_OVER_ERROR = new CodeMsg(500400, "秒杀商品已售罄");

    // 订单模块 5005xx
    public static final CodeMsg REPEACT_CLICK_ERROR = new CodeMsg(500501, "秒杀商品重复点击");

    private int code;
    private String msg;

    private CodeMsg() {
    }

    private CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public CodeMsg fillArgs(Object... args) {
        String message = String.format(this.msg, args);
        return new CodeMsg(this.code, message);
    }

}
